package com.webex.ta.hydra.plugin.gui;

import com.webex.ta.hydra.gui.GuiPackage;
import com.webex.ta.hydra.gui.action.ActionHandler;
import com.webex.ta.hydra.gui.action.ActionNames;
import com.webex.ta.hydra.gui.util.ComponentUtil;
import com.webex.ta.hydra.plugin.PluginManager;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by Cisco WebEx.
 * User: vegaz
 * Date: 2010-9-29
 * Time: 13:34:19
 */
public class OpenPluginManager implements ActionHandler {
    private static Set<String> commands = new HashSet<String>();

    static {
        commands.add(ActionNames.PLUGIN_MGR);
    }

    public Set<String> getActionNames() {
        return commands;
    }

    public void doAction(ActionEvent e) {
        PluginManagerDialog dialog = new PluginManagerDialog(GuiPackage.getInstance().getIdeFrame(), false);
        dialog.pack();
        ComponentUtil.centerComponentInWindow(dialog);
        dialog.setVisible(true);
//        try {
//            PluginManager.getInstance().downloadPluginList();
//        } catch (Exception e1) {
//            e1.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
//        }
//        int answer = JOptionPane.showConfirmDialog(GuiPackage.getInstance().getMainFrame(),
//                "Would you like download and install ?",
//                "Download and Install",
//                JOptionPane.YES_NO_OPTION);
//        if (answer == JOptionPane.YES_OPTION) {
//            final PluginManagerDialog.DownloadMonitor monitor = new PluginManagerDialog.DownloadMonitor(GuiPackage.getInstance().getMainFrame());
//            ComponentUtil.centerComponentInWindow(monitor);
//            monitor.setVisible(true);
//            new Thread(new Runnable() {
//                public void run() {
//                    PluginManager.getInstance().install("Hamal", monitor);
//                    monitor.setVisible(false);
//                }
//            }).start();
//        }
    }
}
